<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="se" uri="http://zc.security/acl"%>
<%
	String productCode = request.getParameter("productCode");
%>
 
<div class="easyui-layout" style="width:100%;height:100%;" fit="true">
    <div data-options="region:'center',split:true">
		<table id="demoData"></table>
	</div>
</div>  
<script>
var demoTable;
var toolbar = [
	<se:hasPermissions actCode="UPDATE">
	{
	text:'图片上传',
    iconCls:'icon-add',
    handler:function(){
    	$.pmsDialog({
    		id:"plug_upload",  //固定ID
    		title:'上传控件',
    		isIf:'true',
    		params:{    //这4个必须填   可
        		"fileType":"img", //必填项  file  or   img or all
        		"fileExtensions":"", //可选值 可指定后缀 即上传类型
        		"oneSelect":'false',
        		"moduleId":"product",
        		"funcId":"product-picture",
        		"dataId":"<%=productCode%>"
        	},
    		method:'post',
    		href:'<c:url value="/views/jsp/upload/com_uploader_s.jsp"/>',
    		width:900,
    		height:464
    	});
    }
},
</se:hasPermissions>
{
	text:'图片删除',
    iconCls:'icon-remove',
    handler:function(){
    	removePicture();
    }
},
{
	text:'备注：图片大小最合适尺寸为：600 x 600,只要正方形,越大越好,系统会自动缩略。',
    
    handler:function(){
    	
    }
}];

function initTable(){
	demoTable = $('#demoData').pDataGrid({
		toolbar:toolbar,
	    columns:[[
				  {field:'ck',checkbox:true},
	              {field:'view',title:'预览',align:'center',formatter:function(value,rows){
						return '<span style="padding:1px;"><a href="'+contentPath+rows.bigPicture+'"   target="_blank"><img src="'+contentPath+rows.smallPicture+'" width="60px;" height="60px;"  /></a></span>';
				  }},
				  {field:'productCode',title:'产品编号',align:'center'},
	              {field:'productName',title:'产品名称',align:'center'},
	              {field:'isDefault',title:'是否默认图',align:'center',formatter:function(value,row){
						if(value==0){
							return '×';
						}
						else if(value==1){
							return '<span style="color:red;font-weight:700;">√</span>';
						}else{
							return '';
						}
		          }},
	              {field:'bigPicture',title:'图片地址',align:'center'},
	              {field:'action',title:'操作',align:'center',formatter:function(value,row){
					return '<a href="javascript:updateEmBProductPicture('+row.pictureId+')">设置默认</a>';
		          }}
	              
	          ]],
	    url:'<c:url value="/product/searchEmBProductPicture.do"/>',  
	    pagination:false,
	    singleSelect:false,
	    queryParams:{
			"productCode":"<%=productCode%>" 
		}
	    
	}); 
}
function removePicture(){
	var row = $('#demoData').datagrid('getSelections');
	if(row.length==0){
		alertWarning("您未选择任何图片!");
		return;
	}
	var param = new Object();
	for(var i=0;i<row.length;i++){
		param['list['+i+'].pictureId']=row[i].pictureId;
	}
	$.pmsAjax({
		url:'<c:url value="/product/deleteBatchEmBProductPicture.do"/>',
		data:param,
		success:function(data){
			if(data.code=="200"){
				alertShow("删除成功");
				demoTable.refresh();
			}else{
				alertError(data.result);
			}
		}
	});
}
function getFiles(obj){
	if(obj.length>0){
		var param = new Object();
		for(var i=0;i<obj.length;i++){
			param['list['+i+'].productCode']="<%=productCode%>";
			param['list['+i+'].smallPicture']=obj[i].relativeFilePath+"small_"+obj[i].fileSysName;
			param['list['+i+'].middlePicture']=obj[i].relativeFilePath+"middle_"+obj[i].fileSysName;
			param['list['+i+'].bigPicture']=obj[i].relativeFilePath+obj[i].fileSysName;
			param['list['+i+'].uploadId']=obj[i].id;
		}
		$.pmsAjax({
			url:'<c:url value="/product/insertBatchEmBProductPicture.do"/>',
			data:param,
			success:function(data){
				if(data.code=="200"){
					alertShow("新增成功");
					$("#plug_upload").dialog('close');
					demoTable.refresh();
				}else{
					alertError(data.result);
				}
			}
		});
	}
}

//设置默认
function updateEmBProductPicture(id){
	var param = {"pictureId":id,"isDefault":1,"productCode":"<%=productCode%>"};
	$.pmsAjax({
		url:'<c:url value="/product/updateEmBProductPictureDefault.do"/>',
		data:param,
		success:function(data){
			if(data.code=="200"){
				alertShow("设置默认成功");
				demoTable.refresh();
			}else{
				alertError(data.result);
			}
		}
	});
}
$(function(){
	initTable();
});


</script>
